#include "NetworkManager.h"

/*construtor*/
NetworkManager::NetworkManager(int tipo){

	if(tipo == SERVER){
		server = new server_network();
		server->listen(porta);

	}else if (tipo == CLIENT){
		network = new network();
	}

}

/*destrutor*/
NetworkManager::~NetworkManager(){

	if(network)
		network->~network();

	if(server)
		server->~server_network();

}

/*conecta cliente ao servidor*/
int NetworkManager::conectClient(const char * host, ){

	return network->connect(host,PORTA);

}

/*envia dados do cliente para o servidor*/
int NetworkManager::sendMessage(void *buf, size_t size, size_t *bytes){

	return network->send(buf,size,socket,bytes);

}

/* recebe dados do servidor*/
int NetworkManager::receive(void *buf, size_t size, size_t * bytes){

	return network->receive(buf, size, bytes);
}

/* fecha conexão*/
int NetworkManager::close(int tipo){

	if(tipo == SERVER)
		network->close();
		
	if(tipo == CLIENT)	
		network->~network();

	return 0;
}

/*aceita conexão [PARA SERVIDOR]*/
int NetworkManager::accept(){

	return server_network->accept();

}

/* recebe dados do cliente... que vai tá na lista de socket*/
int NetworkManager::receive(void *buf, size_t max_size, TCPsocket *socket, size_t *bytes){
	
	return server_network->receive(buf, max_size, socket, bytes);
}

/* broadcast */
int NetworkManager::broadcast(void *buf, size_t size){
	
	return server_network->broadcast(buf,size);
}
